package com.module.home.ui.healthDataDetails

import androidx.core.content.ContextCompat
import com.common.base.app.fragment.BaseVMFragment
import com.common.base.utils.Page
import com.module.home.R
import com.module.home.databinding.HomeFragmentHeartDataDetailsBinding
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2024/11/18
 *
 * 描述：
 *
 * 修订历史：
 *
 */
class HeartDetailsFragment : BaseVMFragment<HomeFragmentHeartDataDetailsBinding, HealthDataDetailsViewModel>() {

//    private val adapter by lazy { SeckillListAdapter(mType) }

    private val classicsFooter by lazy { ClassicsFooter(requireActivity()) }

    companion object {
        fun newInstance(mType: Int = 0,mCycle: String): HeartDetailsFragment {
            val fragment = HeartDetailsFragment()
            fragment.mType = mType
            fragment.mCycle = mCycle
            return fragment
        }
    }

    private var mType: Int = 0
    private var mCycle: String = ""//周期：

    private val page = Page()

    override fun getPlaceholderView() = mViewBinding.placeView

    override fun getViewModel() = HealthDataDetailsViewModel::class.java

    override fun getViewBinding() = HomeFragmentHeartDataDetailsBinding.inflate(layoutInflater)

    override fun initViews() {
        super.initViews()

        //上下拉刷新
        getRefreshFooter()?.let { mViewBinding.pdView.setRefreshFooter(it) }
        mViewBinding.pdView.setRefreshHeader(
            ClassicsHeader(requireActivity()).setAccentColor(
                ContextCompat.getColor(requireActivity(), R.color.text_content_week)
            )
        )
        classicsFooter.setAccentColor(
            ContextCompat.getColor(
                requireActivity(),
                R.color.color_999999
            )
        )
        mViewBinding.pdView.setRefreshFooter(classicsFooter)

//        adapter.apply {
//            adapterAnimation = CustomAnimation1()
//            isAnimationFirstOnly = false
//            mViewBinding.hrv.adapter = this
//        }
    }

    override fun lazyInitData() {
        super.lazyInitData()

//        adapter.data.isNullOrEmpty().yes{
//            mViewBinding.pdView.autoRefresh()
//        }

    }


    override fun initEvents() {
        super.initEvents()
        setErrorRetryListener {
            lazyInitData()
        }

        mViewBinding.pdView.setOnRefreshLoadMoreListener(object : OnRefreshLoadMoreListener {
            override fun onRefresh(refreshLayout: RefreshLayout) {
//                page.reset()
//                adapter.data.clear()
//                adapter.notifyDataSetChanged()
//                mViewBinding.pdView.setEnableLoadMore(true)
            }

            override fun onLoadMore(refreshLayout: RefreshLayout) {
                mViewBinding.pdView.setEnableLoadMoreWhenContentNotFull(false)
                mViewBinding.pdView.finishLoadMoreWithNoMoreData()
            }
        })

//        adapter.setOnItemClickListener { _, view, position ->
//            //防止多次点击
//            if (ViewUtils.isFastClick()) return@setOnItemClickListener
//            adapter.data[position].apply {
//                GoodsRouteUtil.jumpToGoodsDetail(SpuId, SkuId, "购物车")
//            }
//        }

//        mViewContentBinding.tvLoginOut.setOnClickListener(onClick = this)
    }

    private fun finishPdView() {
        mViewBinding.pdView.finishRefresh()
        mViewBinding.pdView.finishLoadMore()
    }
}